package cn.wx.read.neo4j.repository;

import org.neo4j.ogm.model.Result;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import cn.wx.read.neo4j.entity.Neo4jExpert;

/**
 * neo4j 更新专家计算结果
 * @author Administrator
 *
 */
@Repository
public interface ComputeRepository extends Neo4jRepository<Neo4jExpert,Long> { 
	
	/**
	 * compute : 0 代表不需要计算 1 : 代表需要计算
	 */
	@Query(" match(e:expert) where n.compute=1 "
			+ " return distinct ID(e) as id,e.fId as fId,e.citations as citations,e.`h-index` as hIndex "
			+ " limit 1000 ")
	Result loadComputeExperts();
	
	/**
	 * 获取当前作者的图书
	 */
	@Query(" match(e:expert)-[r:write1]->(b:book) where ID(e)={expertId} "
			+ " return distinct ID(b) as id,b.year ")
	Result computeBook(@Param("expertId") Long expertId);
	
	
	/**
	 * 获取当前作者的论文
	 */
	@Query(" match(e:expert)-[r:publish1]->(b:paper) where ID(e)={expertId} "
			+ " return distinct ID(b) as id,b.year ")
	Result computePaper(@Param("expertId") Long expertId);
	
	/**
	 * 获取当前作者的专利
	 */
	@Query(" match(e:expert)-[r:invention]->(b:patents) where ID(e)={expertId} "
			+ " return distinct ID(b) as id,b.year,b.cit ")
	Result computePatents(@Param("expertId") Long expertId);
	
	/**
	 * 更新
	 * book数, patent专利数 , patent-cit专利引用数 , paper 论文数
	 * N-index , A-index , I-index,P-index,g-index
	 * @param expertId
	 */
	@Query(" match(e.expert) where ID(e)={expertId} "
			+ "set e. ")
	void mergeExpert(@Param("expertId") Long expertId);
}
